// Copyright Recursoft LLC 2019-2022. All Rights Reserved.
#pragma once

#include "SmQuestEditorStyle.h"
#include "Styling/SlateStyleRegistry.h"
#include "Styling/CoreStyle.h"
#include "Interfaces/IPluginManager.h"

#define LOCTEXT_NAMESPACE "SmQuestEditorStyle"

// See SlateEditorStyle.cpp
#define IMAGE_BRUSH( RelativePath, ... ) FSlateImageBrush( FSmQuestEditorStyle::InResources( RelativePath, ".png" ), __VA_ARGS__ )

TSharedPtr<FSlateStyleSet> FSmQuestEditorStyle::StyleSetInstance = nullptr;

static const FVector2D Icon16x16(16.0f, 16.0f);
static const FVector2D Icon20x20(20.0f, 20.0f);
static const FVector2D Icon32x32(32.0f, 32.0f);
static const FVector2D Icon40x40(40.0f, 40.0f);
static const FVector2D Icon64x64(64.0f, 64.0f);
static const FVector2D Icon128x128(128.0f, 128.0f);

void FSmQuestEditorStyle::Initialize()
{
	// Only init once.
	if (StyleSetInstance.IsValid())
	{
		return;
	}

	StyleSetInstance = MakeShareable(new FSlateStyleSet(GetStyleSetName()));
	StyleSetInstance->SetContentRoot(FPaths::EngineContentDir() / TEXT("Editor/Slate"));
	StyleSetInstance->SetCoreContentRoot(FPaths::EngineContentDir() / TEXT("Slate"));

	SetIcons();

	FSlateStyleRegistry::RegisterSlateStyle(*StyleSetInstance.Get());
}

void FSmQuestEditorStyle::Shutdown()
{
	FSlateStyleRegistry::UnRegisterSlateStyle(*StyleSetInstance.Get());
	ensure(StyleSetInstance.IsUnique());
	StyleSetInstance.Reset();
}

void FSmQuestEditorStyle::SetIcons()
{
	// Actual pixel size is 40x40, but letting the engine display it at 16x16 looks better.

	// Blueprint types.
	StyleSetInstance->Set("ClassIcon.SmStepObject", new IMAGE_BRUSH(TEXT("Icons/SmStepObjectIcon_16"), Icon16x16));
	StyleSetInstance->Set("ClassThumbnail.SmStepObject", new IMAGE_BRUSH(TEXT("Icons/SmStepObjectIcon_128"), Icon128x128));

	StyleSetInstance->Set("ClassIcon.SmQuestComponent", new IMAGE_BRUSH(TEXT("Icons/SmStepObjectIcon_16"), Icon16x16));
}

FString FSmQuestEditorStyle::InResources(const FString& RelativePath, const ANSICHAR* Extension)
{
	static FString ContentDir = IPluginManager::Get().FindPlugin(TEXT("SmQuest"))->GetBaseDir() / TEXT("Resources");
	return (ContentDir / RelativePath) + Extension;
}

#undef IMAGE_BRUSH

#undef LOCTEXT_NAMESPACE
